package com.briup.estore.web.servlet;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayTradePagePayModel;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.briup.estore.common.result.Result;
import com.briup.estore.common.dto.OrderPayDTO;
import com.briup.estore.common.utils.ALiPayUtils;
import com.briup.estore.common.utils.JsonUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author briup-adam
 * @Date 2023/8/4 下午3:24
 * @Description 支付订单 调用阿里支付
 **/

@WebServlet("/order/pay")
public class OrderPayServlet  extends  BaseServlet {


    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String data = readData(req);
        OrderPayDTO dto = JsonUtils.toObject(data, OrderPayDTO.class);
        String result = ALiPayUtils.pay(dto.getId(), dto.getTotalPrice(), dto.getPathUrl());
        writeData(resp, Result.success(result));
    }
}
